<template>
    <ul class="right-list-container">
        <li v-for="(item, i) in list" :key="i">
            <span @click="handleClick(item)" :class="{ active: item.isSelect }">{{ item.name }}</span>
            <span @click="handleClick(item)" v-if="item.aside" :class="{ active: item.isSelect }" class="aside">{{ item.aside }}</span>
            <!-- 自己递归自己，让自己给自己干活 -->
            <RightList :list="item.children" @select="handleClick" />
        </li>
    </ul>
</template>

<script>
export default {
    name: "RightList",
    props: {
        // [{ name: "xxx", isSelect: true, children: [{ name: "yyy", isSelect: true}]
        list: {
            type: Array,
            default: () => [],
        }
    },
    methods: {
        handleClick(item) {
            // 被点击的对象抛出给父元素
            if (!item.isSelect) {
                this.$emit('select', item);
            }

        }
    }
}
</script>

<style lang="less" scoped>
@import url(~@/styles/var.less);

.right-list-container {
    list-style: none;
    padding: 0;

    .right-list-container {
        margin-left: 1em;
    }

    li {
        min-height: 40px;
        line-height: 40px;
        cursor: pointer;
        font-size: 16px;

        .active {
            color: @warn;
            font-weight: bold;
        }


    }
}

.aside {
    margin-left: 1em;
    font-size: 12px;
    color: @gray;
}
</style>